<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>组织生活详情</title>
	<meta name="decorator" content="default"/>
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/css/bootstrap.css">
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/css/base.css.bak">
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/css/common.css">
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/css/layout.css">
	<script src="<%=request.getContextPath()%>/static/js/jquery-1.10.2.js" type="text/javascript" charset="utf-8"></script>
	<script src="<%=request.getContextPath()%>/static/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="<%=request.getContextPath()%>/static/layer/layer.js"></script>
	<style type="text/css">
		.e-form input{
			padding: 5px 0 !important;
		}
		.form-actions {
			padding-bottom:70px;
		}
		.divBackgroundColor{
			background:#FFB90F;
		}
	</style>
</head>
<body>
<form:form id="inputForm" modelAttribute="homeApprove"  method="post" >
		<div class="guidepost">
			<ul class="guidepost-con">
				<li class="guidepost-item">区市属党工委管理 <i class="icons-12 icons-12-arrowr gray"></i>
				</li>
				<li class="guidepost-item">党员积分审批
				</li>
			</ul>
		</div>	
		<form:hidden path="id"/>
		<input type="hidden" name="checkinfos.organizeLifeId" id="id" value="${homeApprove.id}">
		<input type="hidden" name="checkinfos.approveUserId" id="id" value="${checkinfos.approveUserId }">
		<sys:message content="${message}"/>	
		<div class="container">
			<div class="e-main">
					<div class="mian-box-content pb1">
					<div class="row margin-b10">
						<div class="col-xs-12">
							<div class="row-space">
								<div class="e-box float-e-margins  pb15">
									<div class="e-box-title">
										<h2>活动信息</h2>
									</div>
									
									<div class="e-form pl15 pt15 form-item cler w-100per">
										<div class="col-md-1 tr"><span class="form-item-name w-5xl lh32">年份选择  </span>
										</div>
										<div class="col-md-1">
											<form:input path="column24" disabled="true" htmlEscape="false"  class="input-xlarge required" />
										</div>
									</div>
									<div class="e-form pl15 pt15 form-item cler w-100per">
										<div class="col-md-1 tr"><span class="form-item-name w-5xl lh32">所在组织  </span>
										</div>
										<div class="col-md-1">
											<form:input path="organizationName" disabled="true" htmlEscape="false" class="input-xlarge required" />    
											<input type="hidden" id="organizationid" value="${homeApprove.organizationid}">
										</div>
									</div>
									<div class="e-form pl15 pt15 form-item cler w-100per">
										<div class="col-md-1 tr"><span class="form-item-name w-5xl lh32">活动名称 </span>
										</div>
										<div class="col-md-5">
											<form:input path="lifename" htmlEscape="false" disabled="true" style="width:700px"  class="input-xlarge required" />  
											<input type="hidden" id="organizeLifeId" value="${homeApprove.id}" ></input>                     
										</div>
									</div>
									<div class="e-form pl15 pt15 form-item cler w-100per">
										<div class="col-md-1 tr"><span class="form-item-name w-5xl lh32">起止时间  </span>
										</div>
										<div class="col-md-1">
											 <input id="starttime" readonly="readonly" name="starttime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate required"
													value="<fmt:formatDate value="${homeApprove.starttime}" pattern="yyyy-MM-dd HH:mm"/>"/>	——	
										</div>
										<div class="col-md-1"></div>
										<div class="col-md-1 ml30">
											 <input id="endtime" readonly="readonly" name="endtime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate required"
												value="<fmt:formatDate value="${homeApprove.endtime}" pattern="yyyy-MM-dd HH:mm"/>"/>			
										</div>
									</div>
									<div class="e-form pl15 pt15 form-item cler w-100per">
										<div class="col-md-1 tr"><span class="form-item-name w-5xl lh32">活动地点  </span>
										</div>
										<div class="col-md-5">
											<form:input path="adress" disabled="true" htmlEscape="false" style="width:700px"  class="input-xlarge required"/> 
										</div>
									</div>
									<div class="e-form pl15 pt15 form-item cler w-100per">
										<div class="col-md-1 tr"><span class="form-item-name w-5xl lh32">活动内容  </span>
										</div>
										<div class="col-md-5" style="width:700px;">
											<form:textarea id="contentzy" htmlEscape="true" disabled="true" path="contentzy" rows="4" maxlength="200" class="input-xxlarge"/>
											<sys:ckeditor replace="contentzy" height="150"/>
										</div>
									</div>
									<div class="e-form pl15 pt15 form-item cler w-100per">
										<div class="col-md-1 tr"><span class="form-item-name w-5xl lh32">资料照片  </span></div>
										<div class="controls">	
											<c:forEach var="map" items="${yyzlmap}">
												<div style="float:left">
											 		<img alt="${map.key}" src="${map.value}" style="width:300px;">
												</div>
											</c:forEach>	
										</div>	
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="mian-box-content pt1">
					<div class="row margin-b10">
						<div class="col-xs-12">
							<div class="row-space">
								<div class="e-box float-e-margins  pb15">
									<div class="e-box-title">
										<h2>党员积分内容</h2>
										<div class="e-box-toolbar">
											<div class="btn-group">
												<input class="btn" style="width:85px" data-toggle="modal" onclick="queryPersonAssessmentInfo()" value="查看积分说明" data-target="#modal-del"/>
											</div>
										</div>
									</div>
									<div id="personS">
										<c:forEach var='item' items='${personScoreDetailList}' varStatus='i'>
											<div id="dyjs" class="dyjs">
												<div class="e-form pl15 form-item w-100per cler pt10 pb10">
													<div class="col-md-1 tr"><span class="form-item-name w-5xl lh32">积分内容</span>
													</div>
													<div class="col-md-9">
														<input style="width:760px" type="text" disabled readonly="readonly" class="input-medium" value="${item.personAssessmentInfoTitle}"/>
														<input type="hidden" value="${item.personAssessmentInfoId}"></input>
													</div>
												</div>
												<div class="form-item e-form w-100per pl15 cler divGroup">
													<div class="col-md-1 tr"><span class="form-item-name w-5xl lh32">赋分方式 </span></div>
													<div class="col-md-1">
														<input id="dyscoreModeText" value="${item.scoreMode}" type="text"  disabled readonly="readonly" style="width:50px">
													</div>											
													<div class="col-md-2 tr"><span class="form-item-name w-5xl lh32">默认分数 </span></div>
													<div class="col-md-1 ">
														<input id="dyscoreNumber" value="${item.defaultScore}" type="text" disabled readonly="readonly" style="width:50px">
													</div>
													<div class="col-md-2 tr"><span class="form-item-name w-5xl lh32">申请分数 </span></div>
													<div class="col-md-1 ">
														<input id="dyfz" value="${item.score}" type="text" disabled style="width:50px">
													</div>
												</div>
												<div class="form-item e-form w-100per pl15 cler divGroup">
													<div class="col-md-1 tr"><span class="form-item-name w-5xl lh32">类型 </span></div>
													<div class="col-md-1 ">
														<c:if test="${item.type=='1'}">
															<input id="typeText" value="加分"  type="text" disabled readonly="readonly" style="width:50px">
														</c:if>
														<c:if test="${item.type=='2'}">
															<input id="typeText" value="减分"  type="text" disabled readonly="readonly" style="width:50px">
														</c:if>
													</div>
													<div class="col-md-2 tr"><span class="form-item-name w-5xl lh32">上限分值 </span></div>
													<div class="col-md-1 ">
														<input id="dyupperLimitScore" value="${item.upperScore}" type="text" disabled readonly="readonly" style="width:50px">
													</div>
												</div>
											</div>
										</c:forEach>
						       		</div>
								</div>
							</div>
						</div>
					</div>
				</div>

				<div class="mian-box-content pt1">
					<div class="row margin-b10">
						<div class="col-xs-12">
							<div class="row-space">
								<div class="e-box float-e-margins  pb15">
									<div class="e-box-title">
										<h2>党员积分明细</h2>
										<div class="e-box-toolbar" style="float:left;">
											<span style="color:red;line-height:30px;">(颜色标出的记录已超过该积分项年度上限 或 拒绝申请)</span>
										</div>
									</div>
									<div class="e-box-content p-xs">
										<div id="tab8-2" class="tab-pane">
											<table class="e-table ">
												<thead>
													<tr>
														<th><b>序号</b></th>
														<th><b>姓名</b></th>
														<th><b>性别</b></th>
														<th><b>记录方式</b></th>
														<th><b>积分内容</b></th>
														<th><b>申请积分</b></th>
														<th><b>审核积分</b></th>
														<c:if test="${homeApprove.shstate=='2'}">
															<th class="tc"><b>操作</b></th>
														</c:if>
													</tr>
												</thead>
												<tbody id="personInfo">
													<c:forEach var='item' items='${organizePersonDetailList}' varStatus='i'>
														<tr id="dy${i.index}" class="<c:if test="${item.isUpperStatus=='1'}">divBackgroundColor</c:if>">
															<td><span style='color:black'>${i.index+1}</span></td>
															<td>${item.column2}</td>
															<td>${item.sex}</td>
															<td>${item.signMode}<input type='hidden' id='signMode' value='${item.signMode}' ></input></td>
															<td>${item.personAssessmentInfoTitle}</td>
															<td>${item.applyScore}</td>
															<td>
																<input type='hidden' id='personId${i.index}' value='${item.personId}' ></input>
																<input type='hidden' id='personAssessmentInfoId${i.index}' value='${item.personAssessmentInfoId}' >
																<c:choose>
																	<c:when test="${homeApprove.shstate=='2'}">
																		<input id="personShScore${i.index}" onchange="changePersonScore('${item.type}','${item.applyScore}','${item.defaultScore}','${item.personId}','${item.personAssessmentInfoId}','${item.column1}','${i.index}',this)" value="${item.checkScore}" name='modelType' type='text' maxlength='20'/>
																	</c:when>
																	<c:otherwise>
																		${item.checkScore}
																	</c:otherwise>
																</c:choose>
															</td>
															<c:if test="${homeApprove.shstate=='2'}">
																<td style='text-align: center;'>
																	<button onclick="rejectPersonScore('${item.type}','${item.personId}','${item.personAssessmentInfoId}','${item.column1}','${i.index}')" style="background:red;color: #FFF;" type="button" class='btn' >拒绝</button>
																</td>
															</c:if>
														</tr>
													</c:forEach>
												</tbody>
											</table>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
				
				<div class="mian-box-content pt1">
					<div class="row margin-b10">
						<div class="col-xs-12">
							<div class="row-space">
								<div class="e-box float-e-margins  pb15">
									<div class="e-box-title">
										<h2>审批意见</h2>
									</div>
									<div class="e-box-content">
										<div class="clearfix e-form margin-t10 pb10 pt10 pl15 pr15">
											${username} &nbsp;&nbsp;&nbsp;  ${homeApprove.checkinfos.shTime}
											&nbsp;&nbsp;&nbsp;
											
											<input id="delFlag" name="checkinfos.approveStatus"  type="radio" value="3"
												<c:if test="${empty homeApprove.shstate or homeApprove.shstate=='2' or homeApprove.shstate=='3'}"> checked="checked"</c:if>>
											<label for="delFlag">同意</label>
											
											<input id="delFlag3" name="checkinfos.approveStatus" type="radio"  value="4"
												<c:if test="${homeApprove.shstate=='4'}"> checked="checked"</c:if>>
											<label for="delFlag3">拒绝</label>
											
											<input id="delFlag2" name="checkinfos.approveStatus" type="radio" value="5" 
												<c:if test="${homeApprove.shstate=='5'}"> checked="checked"</c:if>>
											<label for="delFlag2">退回</label>
										</div>
										
										<div class="clearfix e-form margin-t10 pb10 pt10 pl15 pr15">
											<textarea id="approveContent" name="checkinfos.approveContent" style="width:800px" class="input-xlarge required" rows="4">${homeApprove.checkinfos.approveContent }</textarea>
										</div>
										
										<div class="form-actions" style="float:right;">
											<c:if test="${homeApprove.shstate=='2'}">
												<input id="saveBtn" class="btn btn-primary" onclick="save()" type="button" value="保存"/>&nbsp;&nbsp;&nbsp;
											</c:if>
											<input id="cancelBtn" class="btn btn-primary" type="button" value="返 回" onclick="history.go(-1)"/>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</form:form>
	<script type="text/javascript">
		
		//党员审核积分onchange事件
		function changePersonScore(type,applyScore,defaultScore,personId,personAssessmentInfoId,year,index,obj){
			var score = $(obj).val();
			
			var reg = /^\d+$|^\d+\.\d{0,1}$/gi;
			if(!reg.test(score)){
				layer.msg("审核分数必须是一位小数以内的非负数！");
				$(obj).val(applyScore);
				return false;
			}
			
			if(parseInt(defaultScore) < parseInt(score)){
				layer.msg("审核分数不能大于默认分数");
				$(obj).val(defaultScore);
				return false;
			}
			var isUpper = checkPersonTotalUppper(type,personId,personAssessmentInfoId,year,score);
			if(isUpper){
				layer.msg('申请积分超过上限分值');
				$("#dy"+index).addClass("divBackgroundColor");
			}else{
				$("#dy"+index).removeClass("divBackgroundColor");
			}
		}
		
		//党员积分拒绝操作
		function rejectPersonScore(type,personId,personAssessmentInfoId,year,index){
			if($("#dy"+index).hasClass("divBackgroundColor")){
				var applyScore = $("#personShScore"+index).val();
				var isUpper = checkPersonTotalUppper(type,personId,personAssessmentInfoId,year,applyScore);
				if(isUpper){
					layer.msg('申请积分超过上限分值');
				}else{
					$("#dy"+index).removeClass("divBackgroundColor");
				}
			}else{
				$("#dy"+index).addClass("divBackgroundColor");
			}
		}
		
		//校验党员
		function checkPersonTotalUppper(type,personId,personAssessmentInfoId,year,applyScore){
			var tmp;
			$.ajax({
				url:"${ctx}/approve/activityApprove/checkPersonTotalUppper",
				type:"post",
				dataType:"json",
				async: false,
				data:{
					"personId":personId,
					"personAssessmentInfoId":personAssessmentInfoId,
					"applyScore":applyScore,
					"type":type,
					"column1":year
				},
				success:function(data){
					if(data.result == '1'){
						tmp = true;
					}else {
						tmp = false;
					}
				}
			});
			return tmp;
		}
		
	  	//创建签到党员明细对象
  		function createOrganizePersonDetail(organizeLifeId, personAssessmentInfoId, status, checkScore, personId) {
			var object = new Object();
			object.personId = personId;
			object.organizeLifeId = organizeLifeId;//组织生活id
			object.personAssessmentInfoId = personAssessmentInfoId;//积分id
			object.checkScore = checkScore;//审核分数
			object.status = status;//审核状态
			return object;
		}
	  	
  		 //组织生活
		function createOrganizeLife(id,shstate,shyj,organizePersonDetailList) {
			var object = new Object();
			object.id = id;
			object.shstate = shstate;
			object.shyj = shyj;
			object.organizePersonDetailList = organizePersonDetailList;
			return object;
	    }
		
		//保存事件
		function save(){
			var status = $("input:radio:checked").val();
			var organizeLifeId = $("#organizeLifeId").val();
			var approveContent = $("#approveContent").val();
			
    		//组装签到党员明细		    	
	    	var organizePersonDetailList = new Array();                   
	    	var trs = $("#personInfo").find("tr[id^=dy]");	    	    
    		$(trs).each(function(j, trs) {		  
    			var checkScore = $("#personShScore"+j).val();
    			var personAssessmentInfoId = $("#personAssessmentInfoId"+j).val();
    			var personId = $("#personId"+j).val();
    			var status;
    			if($(this).hasClass("divBackgroundColor")){
    				status = '4';
    				checkScore = '0';
    			}else{
    				status = '3';
    			}
    			var organizePersonDetail = createOrganizePersonDetail(organizeLifeId, personAssessmentInfoId, status, checkScore, personId);
    			organizePersonDetailList.push(organizePersonDetail);		    			
    		});		
    		var organizeLife = createOrganizeLife(organizeLifeId,status,approveContent,organizePersonDetailList);
    		
    		var url = "";
    		if(status=='3'){
    			url = "${ctx}/approve/activityApprove/agreeOrganizeLifeScore";
    		}else if(status=='4' || status=='5'){
    			url = "${ctx}/approve/activityApprove/rejectOrganizeLifeScore";
    		}
    		
    		$.ajax({
				url:url,
				type:"post",
				dataType:"json",
				contentType : 'application/json',
				data:JSON.stringify(organizeLife),
				success:function(data){
					var code = data.code;
					var result = data.result;
					if(code=='200'){
						window.location.href = "${ctx}/approve/personApprove";
						window.parent.layer.msg(result);
					}else if(code=='500'){
						layer.msg(result);
					}
				}
			});
		}
		
		//查询党员积分说明
		function queryPersonAssessmentInfo(){
			var organizationid = $("#organizationid").val();
			layer.open({
			  type: 2,
			  title: '<span style="color:#c00"><b>党员积分说明</b></span>',
			  shadeClose: true,
			  shade: 0.8,
			  area: ['70%', '50%'],										
			  content: '${ctx}/personassessmentinfo/personAssessmentInfo/toQueryPersonAssessmentInfo?orgId='+organizationid+"&mode=2"
			}); 
		}
		
	</script>
</body>
</html>